import csv
import pandas as pd

file = 'Info_Of_RawMaterials.csv'
file2 = 'Products_Score.csv'
fd1 = pd.read_csv(file,engine='python')
fd2 = pd.read_csv(file2)
spaceIndex = []

Ss = []

dfc = fd1['DFC_score']
dfc = dfc.tolist()
for i in range(len(dfc)):
    if dfc[i] == " ":
        spaceIndex.append(i)

lists = []
nums = []

for j in range(len(spaceIndex)):
    if j == len(spaceIndex)-1:
        index = spaceIndex[-1]
        temp = dfc[index+1:-1]
        
        num = len(dfc)-j
        
        for r in range(len(temp)):
            t = int(temp[r])
            s += t
        w = round(s/num,2)
        lists.append(w)
        Ss.append(s)
   
        
    else:
        index1,index2 = spaceIndex[j],spaceIndex[j+1]
        temp = dfc[index1+1:index2]
        s = 0
        
        num = index2-index1
        
        for z in range(len(temp)):
            t = int(temp[z])
            s += t
        w = round(s/num,2)
        lists.append(w)
        Ss.append(s) 
    nums.append(num) 


P = fd2['P_Score']

d = {"DFC_Score":lists,"P_Score":P}

df = pd.DataFrame(d)
df.to_csv("scores.csv",index = False)

